package com.safe.first.domain.order.constants;

import com.safe.first.common.constants.BaseEnum;
import com.safe.first.common.constants.CodeEnum;
import com.safe.first.common.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

/**
 * @author Mickey
 * @since 2022/5/26
 **/
@Getter
@AllArgsConstructor
public enum OrderType implements BaseEnum<OrderType> {
    BASE(0, "普通订单", "baseOrderFactory"),
    GOODS(1, "实物订单", "goodsOrderFactory"),
    ;

    private final Integer code;
    private final String name;
    private final String factory;

    public static OrderType of(Integer code) {
        return Optional.ofNullable(BaseEnum.parseByCode(OrderType.class, code)).orElseThrow(() -> new BizException(CodeEnum.FAIL));
    }
}
